package com.medical.admin.sys.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.medical.admin.sys.common.dto.TitleDto;
import com.medical.admin.sys.entity.Role;
import com.medical.admin.sys.entity.Title;

import java.util.List;


/*
 * @Date : 2024/4/28 上午10:16
 * @Created by Lang
 * @ProjectName : medical-appointment-registration
 */

public interface TitleMapper extends BaseMapper<Title> {
    default Title selectEqName(Title title) {
        LambdaQueryWrapper<Title> like = new LambdaQueryWrapper<Title>().eq(Title::getMarTitleName, title.getMarTitleName());
        return selectOne(like);
    }

    default Object selectEqNameNoSelf(Title title) {
        LambdaQueryWrapper<Title> eq = new LambdaQueryWrapper<Title>()
                .eq(Title::getMarTitleName, title.getMarTitleName())
                .ne(Title::getTitleId, title.getTitleId());
        return selectOne(eq);
    }

    default Integer del(Integer delId,Integer titleStatus){
        LambdaUpdateWrapper<Title> set = new LambdaUpdateWrapper<Title>().eq(Title::getTitleId, delId).set(Title::getMarTitleStatus, titleStatus);
        return update(set);
    }

    default Integer delBatch(List<Integer> delIds){
        LambdaUpdateWrapper<Title> in = new UpdateWrapper<Title>().lambda().set(Title::getMarTitleStatus, 0).in(Title::getTitleId, delIds);
        return this.update(in);
    }

    default Title findByDepartmentName(String titleName){
        LambdaQueryWrapper<Title> queryWrapper = new LambdaQueryWrapper<Title>().eq(Title::getMarTitleName,titleName);
        return this.selectOne(queryWrapper);
    };
}